package crack.lshape;

import java.io.IOException;

import crack.AbstractLshapeUsingSDAElementDemo;

import math2.MathUtilities;
import fem2.AbstractStructuralCrackDemo;
import fem2.Element;
import fem2.MaterialModel;
import fem2.Mesh;
import fem2.MeshGenerator;
import fem2.MeshPart;
import fem2.Model;
import fem2.element.crack_sda.SOSConstantJumpCSTElement2;
import fem2.material.cohesive_law.CohesiveLaw;
import fem2.material.cohesive_law.Mode1SanchoExponentialCohesiveLaw;
import fem2.pre_and_post.GidMeshGenerator;

/**
 * 
 * Lshape with triangle mesh generated by mesh2d
 * 
 * @author hbui
 * 
 */
public class LshapeTriMeshMesh2dSOSConstantJumpCSTElement extends AbstractLshapeUsingSDAElementDemo {

	public LshapeTriMeshMesh2dSOSConstantJumpCSTElement() {
		meshFileName = "mesh5-sos.msh";
	}

	@Override
	public Mesh createMesh() {
		String fn = projectDir + '/' + projectName + '/' + meshFileName;
		MeshGenerator mg = new GidMeshGenerator(fn);
		Mesh mesh = mg.getMesh(2);
		return mesh;
	}

	@Override
	public CohesiveLaw createCohesiveLaw(Model m) {
		double ft = 2.7;
		double Gf = 0.065;
		// double km = -1e5;
		// return new Mode1ExponentialCohesiveLaw(Gf, ft, km);
		return new Mode1SanchoExponentialCohesiveLaw(Gf, ft);
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm, CohesiveLaw cl) {
		// return new SOSConstantJumpCSTElement(mp, mm, cl); //also can work
		return new SOSConstantJumpCSTElement2(mp, mm, cl);
	}

	public static void main(String[] args) throws IOException {

		AbstractStructuralCrackDemo Lshape = new LshapeTriMeshMesh2dSOSConstantJumpCSTElement();

		// double[] lambda = MyLinAlg.createLambdaArray(6.66, 0.1, 7.0);

		// double[] lambda = MyLinAlg.createLambdaArray(6.6, 0.1, 6.7, 0.1, 20);

		// double[] lambda = MyLinAlg.createLambdaArray(6.6, 0.1, 30);

		double[] lambda = MathUtilities.createLambdaArray(6.6, 0.1, 40);

		Lshape.run(lambda);

	}

}
